/********************************************
 * 功能说明: Role实体类对应的基础业务Repository
 * 模块名称:
 * 系统名称:
 * 软件版权: Frank
 * 系统版本: 1.0.0.1
 * 开发人员:
 * 开发时间: 2019-12-18 18:41:08
 * 审核人员:
 * 相关文档:
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************/
package com.spring.arch.uaa.repository;

import com.spring.arch.uaa.model.Role;
import com.spring.arch.uaa.model.QRole;
import com.spring.arch.uaa.model.Role;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
import org.springframework.data.querydsl.binding.QuerydslBindings;
import org.springframework.data.repository.Repository;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
 * Role实体类对应的基础业务Repository
 * @author
 * @version 1.0.0.1
 * @since 2019-12-18 18:41:08
 */
@org.springframework.stereotype.Repository
public interface RoleRepository extends Repository<Role, UUID>,
        QuerydslPredicateExecutor<Role>, QuerydslBinderCustomizer<QRole> {

    Role save(Role model);

    Optional<Role> findById(UUID id);

    Page<Role> findAll(Pageable pageable);

    void delete(Role role);

    Optional<Role> findByCode(String tenantAdminRoleCode);

    List<Role> saveAll(Iterable<Role> models);

    List<Role> findAllById(Iterable<UUID> ids);

    @Override
    default void customize(final QuerydslBindings bindings, final QRole qRole){
        bindings.bind(qRole.name).first((path, value) -> qRole.name.containsIgnoreCase(value));
    }

    boolean existsByCode(String code);

    boolean existsByCodeAndIdNot(String code, UUID id);

    boolean existsByName(String name);

    boolean existsByNameAndIdNot(String name, UUID id);
}

